﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFCouse
{
    /// <summary>
    /// ProgressBarWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ProgressBarWindow : Window
    {
        public ProgressBarWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            pbar.Value = 0;
           
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //for (int i = 0; i <= pbar.Maximum; i++)
            //{
            //    pbar.Value = i;
            //    Thread.Sleep(100);
            //}
            int max = (int)pbar.Maximum;
            Task.Run(() =>
            {
                for (int i = 0; i <= max; i += 5)
                {
                    //确切操作。。。。。
                    pbar.Dispatcher.Invoke(() =>
                    {
                        pbar.Value = i;
                        //  lblValue.Content =(decimal.Parse(((decimal)i/(decimal)100).ToString("0.00"))*100).ToString("0")+" %";
                    });
                    Thread.Sleep(100);

                }
            });
        }

        private void pbar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
          //  lblValue.Content = (double.Parse((e.NewValue /100).ToString("0.00")) * 100).ToString("0") + " %";

        }

     
    }
}
